<template>
  <div class="building-type-table">
    <el-table
      :data="data"
      v-loading="loading"
      style="width: 100%"
      border
      stripe
    >
      <el-table-column prop="id" label="ID" width="80" align="center" />
      
      <el-table-column prop="buildingTypeName" label="建筑类型名称" min-width="150">
        <template #default="{ row }">
          <span class="type-name">{{ row.buildingTypeName }}</span>
        </template>
      </el-table-column>
      
      <el-table-column prop="buildingTypeCode" label="建筑类型编码" width="120" align="center">
        <template #default="{ row }">
          <el-tag type="info" size="small">
            {{ row.buildingTypeCode }}
          </el-tag>
        </template>
      </el-table-column>
      
      <el-table-column prop="description" label="描述" min-width="200" show-overflow-tooltip>
        <template #default="{ row }">
          <span class="description-text">{{ row.description || '-' }}</span>
        </template>
      </el-table-column>
      
      <el-table-column prop="sortOrder" label="排序" width="80" align="center">
        <template #default="{ row }">
          <span class="sort-order">{{ row.sortOrder }}</span>
        </template>
      </el-table-column>
      
      <el-table-column prop="status" label="状态" width="100" align="center">
        <template #default="{ row }">
          <el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
            {{ row.status === 1 ? '启用' : '禁用' }}
          </el-tag>
        </template>
      </el-table-column>
      
      <el-table-column prop="createTime" label="创建时间" width="180" align="center">
        <template #default="{ row }">
          <span class="time-text">{{ formatTime(row.createTime) }}</span>
        </template>
      </el-table-column>
      
      <el-table-column label="操作" width="150" align="center" fixed="right">
        <template #default="{ row }">
          <el-button
            type="primary"
            size="small"
            @click="handleEdit(row)"
            :icon="Edit"
          >
            编辑
          </el-button>
          <el-button
            type="danger"
            size="small"
            @click="handleDelete(row)"
            :icon="Delete"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    

  </div>
</template>

<script setup lang="ts">
import { Edit, Delete } from '@element-plus/icons-vue'
import { formatDateTime } from '@/utils/date'

// Props
interface Props {
  data: any[]
  loading?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  loading: false
})

// Emits
const emit = defineEmits<{
  edit: [row: any]
  delete: [row: any]
}>()

// 方法
const formatTime = (time: string) => {
  return formatDateTime(time)
}

const handleEdit = (row: any) => {
  emit('edit', row)
}

const handleDelete = (row: any) => {
  emit('delete', row)
}
</script>

<style lang="scss" scoped>
.building-type-table {
  .type-name {
    font-weight: 500;
    color: var(--el-text-color-primary);
  }
  
  .description-text {
    color: var(--el-text-color-regular);
    font-size: 14px;
  }
  
  .sort-order {
    color: var(--el-text-color-secondary);
    font-size: 14px;
  }
  
  .time-text {
    color: var(--el-text-color-secondary);
    font-size: 12px;
  }
}
</style>
